package eu.codlab.game.gameba;

import eu.codlab.androidemu.Emulator.FrameUpdateListener;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class VirtualKeypadView extends SurfaceView
implements SurfaceHolder.Callback{
	public VirtualKeypadView(Context context, AttributeSet attrs) {
		super(context, attrs);

		final SurfaceHolder holder = getHolder();
		holder.addCallback(this);

		setFocusableInTouchMode(true);
		requestFocus();
	}

	/*private OnFrameDrawnListener listener;
	public interface OnFrameDrawnListener {
		void onFrameDrawn(Canvas canvas);
	}

	public void setFrameUpdateListener(OnFrameDrawnListener l){
		listener = l;
	}

	public void draw(Canvas canvas){
		if(listener != null)
			listener.onFrameDrawn(canvas);
	}*/

	public void surfaceCreated(SurfaceHolder holder) {
		holder.setFormat(PixelFormat.TRANSLUCENT);
	}

	public void surfaceDestroyed(SurfaceHolder holder) {
	}

	public void surfaceChanged(SurfaceHolder holder,
			int format, int width, int height) {
	}

	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int specWidth = MeasureSpec.getSize(widthMeasureSpec);
		int specHeight = MeasureSpec.getSize(heightMeasureSpec);
		int w, h;
		w = specWidth;
		h = specHeight;
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		//setMeasuredDimension(w, h);
	}
/*
	@Override
	public void onFrameDrawn(Canvas canvas) {
		//this.invalidate();
		if(!wasinvalidate){
			canvas = this.getHolder().lockCanvas();
			//listener.onFrameDrawn(canvas);
			getHolder().unlockCanvasAndPost(canvas);
			wasinvalidate = true;
		}
	}

	boolean wasinvalidate = false;*/
}
